package com.woniu.supermarket.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.supermarket.entity.Goods;
import com.woniu.supermarket.mapper.GoodsMapper;
import com.woniu.supermarket.service.IGoodsService;
import com.woniu.supermarket.util.CodeCreateUtil;
import com.woniu.supermarket.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements IGoodsService {

    @Autowired
    GoodsMapper goodsMapper;

    //添加
    @Override
    public int addGoods(Goods goods){
        int i = goodsMapper.insert(goods);
        return i;
    }

    //修改
    @Override
    public int modifyGoods(Goods goods){
        int i = goodsMapper.updateByPrimaryKey(goods);
        return i;
    }
    //单个删除
    @Override
    public int removeGoods(int id){
        int i = goodsMapper.deleteByPrimaryKey(id);
        return i;
    }

    //批量删除
    @Override
    public int removeBatchGoods(int[] ids){
        int i = goodsMapper.deleteBatchGoods(ids);
        return i;
    }

    //分页查
    @Override
    public PageInfo<GoodsVo> findGoodsByCons(Integer now,Integer size,String name,Integer typeId){
        PageHelper.startPage(now,size);
        List<GoodsVo> lists = goodsMapper.selectGoodsByCons(name, typeId);
        return new PageInfo<>(lists);
    }

    @Override
    public int findGidByCode(String code) {
        return goodsMapper.getGidByCode(code);
    }

    @Override
    public int addGoodsVo(GoodsVo goodsvo) {

        return goodsMapper.updateByCode(goodsvo);
    }

    @Override
    public int editGoodsVo(GoodsVo goodsvo) {
        return goodsMapper.updateByGid(goodsvo);
    }



}
